package com.heima.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.pojo.dto.Node;
import com.heima.pojo.dto.NodeDto;
import com.heima.pojo.dto.NodeQuery;
import com.heima.pojo.vo.NodeVo;
import com.heima.pojo.vo.PageVo;
import com.heima.service.INodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 点位表 前端控制器
 * </p>
 *
 * @author 存折
 * @since 2024-10-19
 */
@RestController
@RequestMapping("/api/vm-service/node")
@Slf4j
public class NodeController {
    @Autowired
    private INodeService iNodeService;

    @GetMapping("/search")
    public PageVo<NodeVo> query(NodeQuery nodeQuery){

        return   iNodeService.query(nodeQuery);
    }

    @PostMapping
    public Boolean add(@RequestBody Node node){

        node.setUpdateTime(LocalDateTime.now());
        node.setCreateTime(LocalDateTime.now());
        iNodeService.save(node);
        return true;
    }

    @GetMapping("/vmList/{id}")
    public List<NodeDto> NodeDetail(@PathVariable Long id){
       List<NodeDto> list =iNodeService.selectDetail(id);
           return list;
    }

    @PutMapping("/{id}")
    public Boolean update(@RequestBody Node node,@PathVariable Long id){
        node.setId(id);
        iNodeService.updateById(node);
        return true;
    }
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Long id){
        log.info("接收到的参数为:{}",id);
        iNodeService.removeById(id);
        return true;
    }
}
